home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / SWAG9605.DDD / 0136_Create a Character Pyramid.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-05-31  |  2.0 KB  |  69 lines

  1. {
  2. >I need to do two programs and I am unsure of what to do with them.  If
  3. >anyone could help me with the code or the steps necessary to write the
  4. >programs it would be greatly appreciated.  Thank you.  Here's what I
  5. >need to do:
  6.  
  7. >First program: A program that reads a char. from "A" to "Z" as input
  8. >to produce output in the shape of a pyramid composed of the letters up
  9. >to and including the letter that is input.  Example:
  10. >                                            A
  11. >                                         ABA
  12. >                                      ABCBA
  13. >                                    ABCDCBA
  14.  
  15. Here is one way to do the pyramid of characters. }
  16.  
  17. Program Char_Pyramid;
  18. { <clifpenn@airmail.net   4/16/96   12:30 AM   Borland Turbo v 6.0
  19.   From a single character input in ['A'..'Z'] a pyramid of chars is
  20.   formed as follows:
  21.                        A                             A
  22.   ch1 := 'C' gives    ABA      ch1 := 'D' gives     ABA      etc.
  23.                      ABCBA                         ABCBA
  24.                                                   ABCDCBA   }
  25. USES CRT;
  26. Label Finis;
  27.  
  28. CONST
  29. Esc = Chr(27);
  30.  
  31. VAR
  32. ch1, ch2:Char;
  33. s, s1, s2:String;
  34. fld:Integer;
  35.  
  36. BEGIN
  37.      Repeat
  38.            ClrScr;
  39.            Write('Input a letter, (Esc to quit): ');
  40.            fld := 40;
  41.            s1 := '';
  42.            s2 := '';
  43.  
  44.            Repeat
  45.                  ch1 := UpCase(ReadKey);
  46.            Until ch1 in [Esc, 'A'..'Z'];
  47.  
  48.            If ch1 = Esc then Goto Finis;
  49.  
  50.            Begin
  51.                 Writeln(ch1);
  52.                 For ch2 := 'A' to  ch1 Do
  53.                 Begin
  54.                      s1 := s1 + ch2 ;  (* forward string segment *)
  55.                      s := s1 + s2 ;    (* forward + reversed chars *)
  56.                      Writeln(s:fld);   (* centered on screen *)
  57.                      Inc(fld);
  58.                      s2 := ch2 + s2;   (* next reversed str segment *)
  59.                 End;
  60.            End;
  61.            Write('Press enter to continue');
  62.            Readln;
  63. Finis:
  64.      Until ch1 = Esc;
  65. END.
  66.  
  67.  
  68.  
  69.